/*
 * CodeListIterator.cpp
 *
 *  Created on: 4 May 2010
 *      Author: Savramis Sartios
 */

#include "CodeListIterator.h"
#include "../../../Exceptions/EmptyIterator.h"
#include "../../../Exceptions/NullPointer.h"
#include "../../../Exceptions/OutOfBound.h"
#include "../List/CodeList.h"
CodeListIterator::CodeListIterator() {
	throw EmptyIterator("Iterator must be created only for a container");
}

CodeListIterator::CodeListIterator(const ICodeList *list){
	setList(list);
	setCurrent(0);
}

CodeListIterator::~CodeListIterator() {

}

bool	CodeListIterator::setList(const ICodeList *list){
	if(0!=list){
		list_=const_cast<ICodeList*>(list);
		return true;
	}
	throw NullPointer("List can't be null");
}

void CodeListIterator::first(){
	this->setCurrent(0);
}

void CodeListIterator::next(){
	increaseCurrent();
}

bool CodeListIterator::isDone()const{
	return current_>=list_->count();
}

bool	CodeListIterator::increaseCurrent(){
	current_++;
	return true;
}

bool	CodeListIterator::setCurrent(const int current){
	current_=current;
	return true;
}

string	CodeListIterator::getCurrent()const{
	if(this->isDone()){
		throw OutOfBound("Current pointer is out of container bounds");
	}
	return list_->getElement(current_);
}
